/**
* \file dunGraphs.h
* \brief Construction, parsing and destruction of graphs.
* \author Panos Baroudjian
**/

#ifndef DUNGRAPHS_H_
# define DUNGRAPHS_H_

# include <stdlib.h>
# include <stdio.h>
# include "dunQueue.h"
# include "dunHeap.h"
# include <float.h>
# include <limits.h>

#define GSIZE(o) (sizeof(int) + sizeof(t_som)*(o))
#define room(g,s) (g->lsom[(s)])
#define succ(g,s) (room(g,s)->succ)
#define pred(g,s) (room(g,s)->pred)
#define next(p) ((p)=(p)->next)
#define EMPILER(p,s,d) (p[s] = stackPush(d, p[s]))

#define _DEAD_ 	-1
#define _NP_	-32767
#define _INF_	32766

typedef enum RoomType
{
	Normal = 0,
	Brewery = 1,
	Monster = 2,
	Dead = 3
} RoomType;

typedef struct s_graph *t_graph;
typedef struct s_som   *t_som;
typedef struct s_adj   *t_adj;

typedef struct s_couple
{
	int pere, life;
} t_couple;

struct s_som
{
	int	som;
	t_adj	succ, pred;
	RoomType room;
	int value;
};

struct s_adj
{
	float	cost;
	int	vsom;
	t_adj	next;
};

struct s_graph
{
	int		order;
	t_som	lsom[1];
};


t_graph graphCreate(int order);

void graphAddArc(t_graph g, int s, int d, float c);

int graphComputeCost(t_graph g, int life, dunQueue verts);

dunQueue graphSeekPath(t_graph g, int life, int s, int d);

int graphDijkstra(t_graph g, int src, int dst, int life, dunQueue* pere);

void graphPrint(t_graph g);

void graphRelaxArc(t_heap *h, int ps, t_adj pa, int* pere, int *dist);

void graphGetStates(t_graph g, int s, int life, dunQueue* outLife, dunQueue* outRoom);

float heur(t_graph g, int som, int life, int dst, float* dist);

int* computeManhattan(t_graph g, int dst);

#endif /* !DUNGRAPHS_H_ */
